package com.inderlab.jpin;

import javassist.CannotCompileException;
import javassist.expr.ExprEditor;
import javassist.expr.MethodCall;

public class JPEditor extends ExprEditor
{
	@Override
	public void edit(MethodCall m) throws CannotCompileException
	{
		String name = m.getMethodName();
		long st,et = 0;

		//------------------------------------------------------------
		System.out.print("--jpin--[ Method Editor ]--["+name+"]");
		st = System.nanoTime();
		//------------------------------------------------------------

		try {
			if(name.equals("test"))
			{
				//m.replace("$0.test2($$);");
				System.out.print("**");
				m.getMethod().insertBefore("{ System.out.println(System.nanoTime()); }");
			}				
		} catch(Exception e) 
		{
			System.out.println("--jpin--[ Exception ] : "+e);
		}

		//------------------------------------------------------------
		et = System.nanoTime() - st;
		System.out.println("  "+et);		
		//------------------------------------------------------------

	}
}
